package cn.kgc.itrip.biz.controller;

import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.vo.order.ItripAddHotelOrderVO;
import cn.kgc.itrip.beans.model.vo.order.ItripModifyHotelOrderVO;
import cn.kgc.itrip.beans.model.vo.order.ValidateRoomStoreVO;
import cn.kgc.itrip.beans.model.vo.order.itripSearchOrderVo;
import cn.kgc.itrip.biz.service.ItripHotelOrderService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 阿泽
 */
@Controller
@RequestMapping("/api/hotelorder")
public class hotelordercontroller {

    /**
     * 修改订房日期验证是否有房
     * POST /api/hotelorder/validateroomstore
     */
    @Resource
    ItripHotelOrderService itripHotelOrderService;

    @RequestMapping(value = "/validateroomstore", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse validateroomstore(@RequestBody ValidateRoomStoreVO validateRoomStoreVO) {

        return itripHotelOrderService.validateroomstore(validateRoomStoreVO);
    }

    /**
     * GET /api/hotelorder/getpersonalorderinfo/{orderId}
     * Description
     * 根据订单ID查看个人订单详情
     */
    @RequestMapping(value = "/getpersonalorderinfo/{orderId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse getpersonalorderinfo(@PathVariable Integer orderId) {
        return itripHotelOrderService.getpersonalorderinfo(orderId);
    }

    /**
     * 根据个人订单列表，并分页显示
     * POST /api/hotelorder/getpersonalorderlist
     */

    @RequestMapping(value = "/getpersonalorderlist", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getpersonalorderlist(@RequestBody itripSearchOrderVo itripSearchOrderVO, HttpServletRequest request) {
        return itripHotelOrderService.getpersonalorderlist(itripSearchOrderVO, request.getHeader("token"));
    }


    /**
     * 根据订单ID查看个人订单详情-房型相关信息
     * GET /api/hotelorder/getpersonalorderroominfo/{orderId}
     */

    @RequestMapping(value = "/getpersonalorderroominfo/{orderId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse getpersonalorderroominfo(@PathVariable Integer orderId) {
        return itripHotelOrderService.getpersonalorderroominfo(orderId);
    }

    /**
     * 任务调度测试，每隔十秒钟调用一下此方法
     */
    @Scheduled(cron = "0/1800 * * * * ?")
    public void scannerOrderByCancel() {
        itripHotelOrderService.updateOrderStatus(1);
        System.out.println("任务调度测试。。。。。当前时间是" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    @Scheduled(cron = "0/7200 * * * * ?")
    public void scannerOrderBySuccess() {
        itripHotelOrderService.updateOrderStatus(2);
        System.out.println("任务调度测试。。。。。当前时间是" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 生成订单前,获取预订信息
     * POST /api/hotelorder/getpreorderinfo
     */
    @RequestMapping(value = "/getpreorderinfo", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getpreorderinfo(@RequestBody ValidateRoomStoreVO validateRoomStoreVO, HttpServletRequest httpServletRequest) {
        return itripHotelOrderService.queryStore(validateRoomStoreVO, httpServletRequest.getHeader("token"));
    }

    /**
     * 生成订单
     * POST /api/hotelorder/addhotelorder
     */
    @RequestMapping(value = "/addhotelorder", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse addhotelorder(@RequestBody ItripAddHotelOrderVO itripAddHotelOrderVO, HttpServletRequest request) {
        return itripHotelOrderService.addhotelorder(itripAddHotelOrderVO, request.getHeader("token"));

    }


    /**
     *
     * http://localhost:6060/biz/api/hotelorder/queryOrderById/148
     * 根据订单ID获取订单信息
     * GET /api/hotelorder/queryOrderById/{orderId}
     */
    @RequestMapping(value = "/queryOrderById/{orderId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse addhotelorder(@PathVariable Long orderId,HttpServletRequest request) throws Exception {
        return itripHotelOrderService.queryOrderById(orderId,request);

    }

    /**
     *  修改订单的支付方式和状态
     *     POST /api/hotelorder/updateorderstatusandpaytype
     */
    @RequestMapping(value = "/updateorderstatusandpaytype", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse updateorderstatusandpaytype(@RequestBody ItripModifyHotelOrderVO orderVO, HttpServletRequest request) throws Exception {
        return itripHotelOrderService.updateOrderStatusAndPayType(orderVO,request);

    }

    /**
     * 支付成功后查询订单信息
     * POST /api/hotelorder/querysuccessorderinfo/{id}
     */













}
